home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST7-18.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  1KB  |  53 lines

  1. ;
  2. ; *** Listing 7-18 ***
  3. ;
  4. ; Performs fast, compact bit-doubling of a byte in AL
  5. ; to a word in AX by using two nibble look-ups. Overall
  6. ; code length and performance are improved by
  7. ; using XLAT to look up the nibbles.
  8. ;
  9. ; Macro to double each bit in a byte.
  10. ;
  11. ; Input:
  12. ;    AL = byte to bit-double
  13. ;
  14. ; Output:
  15. ;    AX = bit-doubled word
  16. ;
  17. ; Registers altered: AX, BX, CL
  18. ;
  19. DOUBLE_BYTE    macro
  20.     mov    ah,al    ;set aside the byte to look up
  21.     mov    cl,4    ;make a look-up pointer out of the
  22.     shr    al,cl    ; upper nibble of the byte (XLAT
  23.             ; uses AL as an index pointer)
  24.     mov    bx,offset DoubledNibbleTable
  25.             ;XLAT uses BX as a base pointer
  26.     xlat        ;look up the doubled value of the
  27.             ; upper nibble
  28.     xchg    ah,al    ;store the doubled upper nibble in AH
  29.             ; and get back the value to double
  30.     and    al,0fh    ;make a look-up pointer out of the
  31.             ; lower nibble of the byte
  32.     xlat        ;look up the doubled value of the
  33.             ; lower nibble of the byte
  34.     endm
  35. ;
  36.     jmp    Skip
  37. DOUBLED_VALUE=0
  38. DoubledNibbleTable    label    byte
  39.     db    000h, 003h, 00ch, 00fh
  40.     db    030h, 033h, 03ch, 03fh
  41.     db    0c0h, 0c3h, 0cch, 0cfh
  42.     db    0f0h, 0f3h, 0fch, 0ffh
  43. ;
  44. Skip:
  45.     call    ZTimerOn
  46. BYTE_TO_DOUBLE=0
  47.     rept    100
  48.     mov    al,BYTE_TO_DOUBLE
  49.     DOUBLE_BYTE
  50. BYTE_TO_DOUBLE=BYTE_TO_DOUBLE+1
  51.     endm
  52.     call    ZTimerOff
  53.